import time

from selenium.webdriver.common.by import By

from Base.BasePage import BasePage


class Application(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # 切换身份
        self.borrowingAccount = (By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[1]/a/em')
        # 点击额度申请
        self.aplay = (By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]')
        # 填写金额
        self.aplay_money = (By.XPATH, '//*[@id="amount_account"]')
        # 填写备注
        self.market = (By.XPATH, '//*[@id="mamountapply"]/div[3]/textarea')
        # 填写验证码
        self.verifycode = (By.XPATH, '//*[@id="verifycode"]')
        # 提交
        self.submit = (By.XPATH, '//*[@id="mamountapply"]/div[5]/input')
        #    成功断言
        self.success = (By.XPATH, '//*[@id="amount_list"]/tr/td[3]')

    def application(self, money, market, verifycode):
        """
        额度申请提交
        :param money:金额
        :param market:备注
        :param verifycode:验证码
        :return:无
        """
        self.click_element(self.borrowingAccount)
        time.sleep(1)
        self.click_element(self.aplay)
        self.base_clear_input(self.aplay_money, money)
        self.base_clear_input(self.market, market)
        self.base_clear_input(self.verifycode, verifycode)
        self.click_element(self.submit)

    def success_assert(self):
        """
        成功断言
        :return:
        """
        result = self.get_element(self.success).text
        return result
